package dev.alm.reggietakeoutservice.service.impl;

import dev.alm.reggietakeoutservice.service.JedisService;
import dev.alm.reggietakeoutservice.utils.JedisUtil;
import org.springframework.stereotype.Service;
import redis.clients.jedis.Jedis;

@Service
public class JedisServiceImpl implements JedisService {
    @Override
    public String get(String key) {
        Jedis jedis = JedisUtil.getJedisPoolInstance().getResource();
        String value = jedis.get(key);
        JedisUtil.release(jedis);
        return value;
    }

    @Override
    public String set(String key, String value) {
        Jedis jedis = JedisUtil.getJedisPoolInstance().getResource();
        String set = jedis.setex(key, 60 * 60, value);
        JedisUtil.release(jedis);
        return set;
    }

    @Override
    public Long del(String key) {
        Jedis jedis = JedisUtil.getJedisPoolInstance().getResource();
        Long del = jedis.del(key);
        JedisUtil.release(jedis);
        return del;
    }
}
